using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using EZCRS.HCMS.DataAcl;
using EZCRS.HCMS.Bll.userinfo;
using EZCRS.HCMS.Web;

namespace EZCRS.HCMS.Web.manage.carduser
{
    public partial class cardnumb_list : ManageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Titlepage1.initlabnew = "<a href=\"cardnumb_add.aspx\"><img src=\"../../image/new.gif\" border=\"0\" /></a>";
                CheckModule(17);

                BtnDel.Attributes.Add("onclick", "javascript:return confirm('" + Resources.Site.SystemConfirmDelete + "');");
                //ImgReturn.Attributes.Add("onclick", "history.back();return false;");
            }
        }
        protected void BtnSearch_Click(object sender, EventArgs e)
        {
            getdata();
        }
        private void getdata()
        {
            lst_nousedcardnumber.Items.Clear();

            string Strwhere = "";
            if (txt_nousedcardnumber.Text.Trim() != "")
            {
                Strwhere += " and cardnumber like '%" + txt_nousedcardnumber.Text.Trim().Replace("'", "") + "%'";
            }
            Strwhere += " and orgid = " + BasGroupId +" and (uid is null or uid='')";
           // Strwhere += " and orgtype = " + CurrentOrgType;

            Bllcardinfo ACN = new Bllcardinfo();
            DataTable dt= ACN.CardNumb_List(Strwhere);

            foreach (DataRow dr in dt.Rows)
            {
                lst_nousedcardnumber.Items.Add(new ListItem(dr["cardnumber"].ToString(), dr["cardid"].ToString()));
            }
        }

       
        protected void BtnDel_Click(object sender, EventArgs e)
        {
            string cardid = CFun.GetListControlSelected(lst_nousedcardnumber,",");
            Bllcardinfo ACN = new Bllcardinfo();
            if (ACN.CardNumb_Del(CFun.CutComma(cardid)))
            {
                DataAcl.Common.SaveLog(BasUserId.ToString(), BasHotelId.ToString(), BasGroupId.ToString(), 57, "");
                Response.Write(CFun.AlertMeg(Resources.Site.LabCardNumber + Resources.Site.SystemDeleteSuccess, "", "cardnumb_list.aspx"));
            }
            else
                Response.Write(CFun.AlertMeg(Resources.Site.SystemError, "back", ""));
        }

        private DataTable getData()
        {
            string Strwhere = "";
            if (txt_nousedcardnumber.Text.Trim() != "")
            {
                Strwhere += " and cardnumber like '%" + txt_nousedcardnumber.Text.Trim().Replace("'", "") + "%'";
            }
            Strwhere += " and orgid = " + BasGroupId + " and (uid is null or uid='')";
           // Strwhere += " and orgtype = " + CurrentOrgType;

            Bllcardinfo ACN = new Bllcardinfo();
            return ACN.CardNumb_List(Strwhere, "");
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            DataTable dt = getData();
            CFun.CreateTXT(dt, "cardnumber.txt");
        }

        protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
        {
            DataTable dt = getData();
            
            CFun.CreateEXCEL(dt, "cardnumber.xls");
        }
    }
}
